/**
 * 输入: bookings = [[1,2,10],[2,3,20],[2,5,25]], n = 5
 * 输出: [10,55,45,25,25]
 * 解释:

 * 航班:        1   2   3   4   5
 * 预定1:       10  10
 * 预定2:           20  20
 * 预定3:           25  25  25  25

 * 结果:        10  55  45  25  25
 *
 * 输入: bookings = [[1,4,10],[3,6,20],[2,5,25]], n = 6
 */

export const bookingStatus = (bookings, n) => {
  const result = new Array(n).fill(0)
  bookings.map(list => {
    result[list[0] - 1] += list[2]
    result[list[1] - 1] += list[2]
  })
  return result
}

export function bookingStatisPerformance(bookings, n) {
  const result = new Array(n).fill(0)
  bookings.forEach(booking => {
    result[booking[0] - 1] += booking[2]
    result[booking[1]] += -booking[2]
  });
  for (let i = 1; i < n; i++) {
    result[i] += result[i - 1]
  }
  result.pop()
  return result
}

export function bookingStatis(bookings, n) {
  const result = new Array(n).fill(0)
  bookings.forEach(booking => {
    const [first, last, count] = booking
    for (let i = first - 1; i < last; i++) {
      result[i] += count
    }
  });
  return result
}